package com.fyzk.activity.lottery.jc.beidan;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.fyzk.activity.lottery.jc.football.newJz.data.QQListView;
import com.tyjc.lottery.R;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by fanxs11 on 16/4/26.
 */
public class BeiDan_BF_Adapter extends BeiDanAdapter{

    protected int zk_bg_color;
    protected int zk_txt_color;

    public BeiDan_BF_Adapter(Context context, List<BeiDanBean> infos, QQListView listView, OnBeiDanCheckBallListener listener) {
        super(context, infos, listView, listener);
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {

        ChildViewHolder childViewHolder;
        final BeiDanChildBean info = infos.get(groupPosition).childBeen.get(childPosition);
//
        if (convertView == null) {
            childViewHolder = new ChildViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.beidan_list_child_bf, null);
            childViewHolder.matchNum_tv = convertView.findViewById(R.id.beidan_list_matchNum_tv);
            childViewHolder.matchName_tv = convertView.findViewById(R.id.beidan_list_matchName_tv);
            childViewHolder.endSaleTime_tv = convertView.findViewById(R.id.beidan_list_endSaleTime_tv);
            childViewHolder.home_tv = convertView.findViewById(R.id.beidan_list_home);
            childViewHolder.away_tv = convertView.findViewById(R.id.beidan_list_away);
            childViewHolder.zk_cb = convertView.findViewById(R.id.beidan_list_bf_zk);

            convertView.setTag(childViewHolder);
        } else {
            childViewHolder = (ChildViewHolder) convertView.getTag();
        }

        childViewHolder.matchNum_tv.setText(info.getMatchNum()+"");
        childViewHolder.matchName_tv.setText(info.getMatchName());
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
        String endTimeStr = simpleDateFormat.format(new Date(info.getEndSaleTime()));
        childViewHolder.endSaleTime_tv.setText(endTimeStr+"截止");
        childViewHolder.home_tv.setText(info.getHomeTeam());
        childViewHolder.away_tv.setText(info.getAwayTeam());

        childViewHolder.zk_cb.setText(info.bf_zk);

        if (!info.bf_zk.equals(BeiDanChildBean.BF_ZK_DEFAULT)) {
            zk_bg_color = context.getResources().getColor(R.color.color_FF4258);
            zk_txt_color = context.getResources().getColor(R.color.white);
        } else {
            zk_bg_color = context.getResources().getColor(R.color.white);
            zk_txt_color = context.getResources().getColor(R.color.color_666666);
        }
        childViewHolder.zk_cb.setBackgroundColor(zk_bg_color);
        childViewHolder.zk_cb.setTextColor(zk_txt_color);

        childViewHolder.zk_cb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (isMax(info.checkNum, null)) {
                    return;
                }
                if (listener != null) {
                    listener.onZhanKaiClick(info);
                }
            }
        });

        jiSuanChangCi();

        return convertView;
    }

    @Override
    protected void jiSuanChangCi() {
        changCi = 0;
        for (int i = 0; i < infos.size(); i++) {
            List<BeiDanChildBean> childBeens = infos.get(i).childBeen;
            for (int j = 0; j < childBeens.size(); j++) {
                if (!childBeens.get(j).bf_zk.equals(BeiDanChildBean.BF_ZK_DEFAULT)) {
                    changCi++;
                }
            }
        }
        if (listener != null) {
            listener.onCheckBall(changCi);
        }
    }

    private class ChildViewHolder {
        TextView matchNum_tv;
        TextView matchName_tv;
        TextView endSaleTime_tv;
        TextView home_tv;
        TextView away_tv;
        TextView zk_cb;
    }

}
